#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QModbusRtuSerialMaster>
#include <QThread>
#include "serialsearchworker.h"
#include "cfg_timerthread.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void InitModbus();
    void disconnnectModbus();
    void  sendReadRequest();
    void  sendReadRequest_input();
    void  handleReadReply_input();
    void  handleReadReply();
    void  sendWriteRequest();
    void  handleWriteReply();
private:
    Ui::MainWindow *ui;
    QModbusRtuSerialMaster *modbusDevice;
    QThread *serialThread;              // 串口搜索线程
    SerialSearchWorker *serialWorker;  // 串口搜索工作对象
    QTimer * timer;
    QTimer * timer_inputreg;
public slots:
    void freshSerialPortCombox(); // 触发搜索串口
    void updateSerialPortList(QStringList portList); // 更新串口列表
    void connectModbus();
    void onTabChanged(int index);
    void cfg_onTimeout();
    void env_onTimeout();
private slots:
    void on_simulate_temp_btn_clicked();
};

#endif // MAINWINDOW_H
